package thread;

import java.util.concurrent.CountDownLatch;

public class demo31 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(()->{
                try {
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName()+"到达终点！");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }

        //裁判等待所有的线程到达
        //当这些线程没有执行完的时候，await就阻塞，所有线程执行完了，await才返回
        latch.await();
        System.out.println("比赛结束！");
    }
}
